package com.neusoft.mapper;

import org.apache.ibatis.annotations.*;

import com.neusoft.po.Currency;

@Mapper
public interface CurrencyMapper {
	//check whether userId has already been in database before calling 'saveCurrency',
	//or server will report error 
	//reference:'public int getUserById(String userId);'
	@Insert("insert into currency(userId, amount) values(${userId}, ${amount})")
	public int saveCurrency(@Param("userId")String userId, @Param("amount")Double amount);
	
	//return a Currency class not int!
	@Select("select * from currency where userId=#{userId}")
	public Currency getCurrencyByUserId(String userId);
	
	@Update("update currency set amount=amount+${addAmount} where userId=${userId}")
	public int addCurrencyByUserId(@Param("addAmount") Double addAmount, @Param("userId") String userId);
	
	@Update("update currency set amount=amount-${minusAmount} where userId=${userId}")
	public int minusCurrencyByUserId(@Param("minusAmount") Double minusAmount, @Param("userId") String userId);
	
}
